package cn.anquing.util;

/**
 * 评分相关
 * 
 * @author wiki
 * 
 */
public class ScoreUtil {

	/**
	 * 根据同盾得分获得分数
	 * 
	 * @param tongdun
	 * @return
	 */
	public static int getScoreByTongdun(int tongdun) {
		int result = 0;
		if (tongdun > 60)
			result = 30;
		else if (tongdun > 55)
			result = 40;
		else if (tongdun > 50)
			result = 50;
		else if (tongdun > 46)
			result = 60;
		else if (tongdun > 42)
			result = 70;
		else if (tongdun > 40)
			result = 80;
		else if (tongdun > 36)
			result = 90;
		else if (tongdun > 33)
			result = 100;
		else if (tongdun > 30)
			result = 110;
		else if (tongdun > 26)
			result = 120;
		else if (tongdun > 23)
			result = 130;
		else if (tongdun > 20)
			result = 140;
		else if (tongdun > 16)
			result = 150;
		else if (tongdun > 13)
			result = 160;
		else if (tongdun > 10)
			result = 170;
		else if (tongdun > 7)
			result = 190;
		else if (tongdun > 5)
			result = 200;
		else if (tongdun > 2)
			result = 180;
		else if (tongdun >= 0)
			result = 150;
		return result;
	}

	/**
	 * 根据芝麻得分获得分数
	 * 
	 * @param tongdun
	 * @return
	 */
	public static int getScoreByZhima(int zhima) {
		int result = 0;
		if (zhima > 940)
			result = 350;
		else if (zhima > 920)
			result = 345;
		else if (zhima > 900)
			result = 330;
		else if (zhima > 880)
			result = 315;
		else if (zhima > 860)
			result = 300;
		else if (zhima > 840)
			result = 285;
		else if (zhima > 820)
			result = 270;
		else if (zhima > 800)
			result = 255;
		else if (zhima > 790)
			result = 240;
		else if (zhima > 780)
			result = 225;
		else if (zhima > 770)
			result = 210;
		else if (zhima > 760)
			result = 195;
		else if (zhima > 750)
			result = 180;
		else if (zhima > 740)
			result = 165;
		else if (zhima > 730)
			result = 150;
		else if (zhima > 720)
			result = 135;
		else if (zhima > 710)
			result = 125;
		else if (zhima > 700)
			result = 105;
		else if (zhima > 690)
			result = 90;
		else if (zhima > 680)
			result = 75;
		else if (zhima > 670)
			result = 60;
		else if (zhima > 660)
			result = 45;
		else if (zhima > 650)
			result = 30;
		else if (zhima > 600)
			result = 15;
		return result;
	}

	/**
	 * 根据芝麻反欺诈得分获得分数
	 * 
	 * @param tongdun
	 * @return
	 */
	public static int getScoreByzhimaCredit(int zhima) {
		int result = 0;
		if (zhima > 98)
			result = 50;
		else if (zhima > 96)
			result = 45;
		else if (zhima > 94)
			result = 40;
		else if (zhima > 92)
			result = 35;
		else if (zhima > 90)
			result = 30;
		else if (zhima > 88)
			result = 25;
		else if (zhima > 86)
			result = 20;
		else if (zhima > 84)
			result = 15;
		else if (zhima > 82)
			result = 10;
		else if (zhima > 80)
			result = 5;
		return result;
	}

	public static int getScoreBySex(String sex) {
		return sex.equals("男") ? 8 : 12;
	}

	/**
	 * 输入的年龄是18-55
	 */
	public static int getScoreByAge(int age) {

		int result = 0;
		if (age > 40)
			result = 20;
		else if (age > 34)
			result = 30;
		else if (age > 22)
			result = 20;
		else
			result = 10;

		return result;
	}

	/**
	 * JD会员等级分
	 * 
	 * @param vipLevel
	 * @return
	 */
	public static int getScoreByJdVipLevel(String vipLevel) {
		int result = 0;

		switch (vipLevel) {
			case "注册会员" :
				result = 20;
				break;

			case "铜牌会员" :
				result = 35;
				break;

			case "银牌会员" :
				result = 40;
				break;

			case "金牌会员" :
				result = 45;
				break;

			case "钻石会员" :
				result = 50;
				break;
		}

		return result;
	}

	/**
	 * 学历分
	 * 
	 * @param vipLevel
	 * @return
	 */
	public static int getScoreByEducationArrangement(String arrangement) {
		int result = 0;

		switch (arrangement) {
			case "博士研究生" :
				result = 50;
				break;

			case "硕士研究生" :
				result = 40;
				break;

			case "本科" :
				result = 35;
				break;

			case "专科" :
				result = 30;
				break;

			case "中专" :
				result = 25;
				break;

			case "高中" :
				result = 20;
				break;

			case "其它" :
				result = 15;
				break;
		}

		return result;
	}

	/**
	 * 白条总额度
	 * 
	 * @param creditlimit
	 *            10000
	 * @return
	 */
	public static int getScoreByJdCreditlimit(Integer creditlimit) {
		int result = 0;

		if (creditlimit > 15000)
			result = 100;
		else if (creditlimit > 12000)
			result = 95;
		else if (creditlimit > 10000)
			result = 90;
		else if (creditlimit > 8000)
			result = 75;
		else if (creditlimit > 5000)
			result = 65;
		else if (creditlimit > 3000)
			result = 55;
		else if (creditlimit > 2000)
			result = 40;
		else if (creditlimit > 1000)
			result = 30;
		else if (creditlimit > 1)
			result = 20;

		return result;
	}

	/**
	 * 跟据JD提额分数获得额度
	 * 
	 * @param score
	 * @return
	 */
	public static Double getUpgradeMoneyByJd(int score) {
		Double result = 0d;
		if (score > 140)
			result = 4500d;
		else if (score > 120)
			result = 4300d;
		else if (score > 100)
			result = 4000d;
		else if (score > 80)
			result = 3500d;
		else if (score > 60)
			result = 3000d;
		else if (score > 40)
			result = 2000d;
		else if (score > 19)
			result = 1000d;

		return result;
	}

	/**
	 * 跟据Taobao提额分数获得额度
	 * 
	 * @param score
	 * @return
	 */
	public static Double getUpgradeMoneyByTaobao(int score) {
		Double result = 0d;
		if (score > 180)
			result = 6000d;
		else if (score > 170)
			result = 5800d;
		else if (score > 160)
			result = 5000d;
		else if (score > 150)
			result = 4800d;
		else if (score > 140)
			result = 4500d;
		else if (score > 130)
			result = 4000d;
		else if (score > 120)
			result = 3500d;
		else if (score > 110)
			result = 3000d;
		else if (score > 50)
			result = 2500d;
		return result;
	}

	/**
	 * 跟据同盾分获得额度
	 * 
	 * @param score
	 * @return
	 */
	public static Double getMoneyByTongDun(int tongdunscore) {
		// 根据同盾分获取我们自己内部的评分
		int score = getScoreByTongdun(tongdunscore);
		Double result = 0d;
		
		if (score > 190)
			result = 4000d;
		else if (score > 180)
			result = 3500d;
		else if (score > 170)
			result = 3000d;
		else if (score > 160)
			result = 2500d;
		else if (score > 150)
			result = 1800d;
		else if (score > 140)
			result = 1600d;
		else if (score > 130)
			result = 1500d;
		else if (score > 120)
			result = 1400d;
		else if (score > 110)
			result = 1300d;
		else if (score > 100)
			result = 1200d;
		else if (score > 90)
			result = 1100d;
		else if (score > 80)
			result = 1000d;
		else if (score > 70)
			result = 800d;
		else if (score > 60)
			result = 700d;
		else if (score > 50)
			result = 600d;
		else if (score > 40)
			result = 500d;
		else if (score > 30)
			result = 400d;
		else if (score > 20)
			result = 300d;
		else if (score > 10)
			result = 200d;
		else if (score > 0)
			result = 100d;
		return result;
	}

	/**
	 * 跟据芝麻信用分获得额度
	 * 
	 * @param score
	 * @return
	 */
	public static Double getMoneyByZhima(int zhimascore) {

		int score = getScoreByZhima(zhimascore);

		Double result = 0d;
		if (score > 345)
			result = 7000d;
		else if (score > 330)
			result = 6000d;
		else if (score > 315)
			result = 5000d;
		else if (score > 300)
			result = 4000d;
		else if (score > 285)
			result = 3000d;
		else if (score > 270)
			result = 2800d;
		else if (score > 255)
			result = 2700d;
		else if (score > 240)
			result = 2600d;
		else if (score > 225)
			result = 2500d;
		else if (score > 210)
			result = 2400d;
		else if (score > 195)
			result = 2300d;
		else if (score > 180)
			result = 2200d;
		else if (score > 165)
			result = 2100d;
		else if (score > 150)
			result = 2000d;
		else if (score > 135)
			result = 1900d;
		else if (score > 120)
			result = 1800d;
		else if (score > 105)
			result = 1700d;
		else if (score > 90)
			result = 1600d;
		else if (score > 75)
			result = 1500d;
		else if (score > 60)
			result = 1300d;
		else if (score > 45)
			result = 1100d;
		else if (score > 30)
			result = 900d;
		else if (score > 15)
			result = 700d;
		else if (score > 0)
			result = 500d;
		return result;
	}

	/**
	 * 跟据年龄分获得额度
	 * 
	 * @param score
	 * @return
	 */
	public static Double getMoneyByAge(int age) {
		int score = getScoreByAge(age);
		Double result = 0d;
		if (score > 20)
			result = 600d;
		else if (score > 10)
			result = 400d;
		else if (score > 0)
			result = 200d;
		return result;
	}

	/**
	 * 跟据性别分获得额度
	 * 
	 * @param score
	 * @return
	 */
	public static Double getMoneyBySex(String sex) {
		int score = getScoreBySex(sex);
		Double result = 0d;
		if (score > 10)
			result = 400d;
		else if (score > 0)
			result = 200d;
		return result;
	}

	/**
	 * 跟据手机在网时长分获得额度
	 * 
	 * @return
	 */
	public static Double getMoneyByMobileRegisterDate(String registerDate) {
		int score = getScoreByMobileRegisterDate(registerDate);
		Double result = 0d;
		if (score > 4)
			result = 100d;
		else if (score > 3)
			result = 80d;
		else if (score > 2)
			result = 50d;
		else if (score > 1)
			result = 20d;
		else if (score > 0)
			result = 10d;
		return result;
	}

	/**
	 * 跟据芝麻反欺诈分获得额度
	 * 
	 * @param score
	 * @return
	 */
	public static Double getMoneyByZhimaCredit(int zhimascore) {

		int score = getScoreByzhimaCredit(zhimascore);

		Double result = 0d;
		if (score > 45)
			result = 1000d;
		else if (score > 40)
			result = 900d;
		else if (score > 35)
			result = 800d;
		else if (score > 30)
			result = 700d;
		else if (score > 25)
			result = 600d;
		else if (score > 20)
			result = 500d;
		else if (score > 15)
			result = 400d;
		else if (score > 10)
			result = 300d;
		else if (score > 5)
			result = 200d;
		else if (score > 0)
			result = 100d;
		return result;
	}

	/**
	 * 跟据芝麻反欺诈分获得额度
	 * 
	 * @param score
	 * @return
	 */
	public static Double getMoneyByZhimaCreditIvsDetail(String zhimaCode) {

		int score = getScoreByZhimaCreditIvsDetail(zhimaCode);

		Double result = 0d;
		if (score > 5)
			result = 200d;
		else if (score > 5)
			result = 100d;
		else if (score > 0)
			result = 50d;
		return result;
	}

	/**
	 * 跟据社保提额分数获得额度
	 * 
	 * @param score
	 * @return
	 */
	public static Double getUpgradeMoneyBySocialsecurity(int score) {
		Double result = 0d;
		if (score > 40)
			result = 1500d;
		else if (score > 30)
			result = 1300d;
		else if (score > 25)
			result = 1000d;
		else if (score > 20)
			result = 900d;
		else if (score > 15)
			result = 700d;
		else if (score > 10)
			result = 600d;
		else if (score > 5)
			result = 500d;
		else if (score > 0)
			result = 300d;
		return result;
	}

	/**
	 * 跟据公积金提额分数获得额度
	 * 
	 * @param score
	 * @return
	 */
	public static Double getUpgradeMoneyByHousefund(String accStatus) {
		int score = getScoreByHouseFund(accStatus);
		Double result = 0d;
		if (score > 40)
			result = 1500d;
		else if (score > 30)
			result = 1300d;
		else if (score > 10)
			result = 1000d;
		else if (score > 0)
			result = 800d;
		return result;
	}

	/**
	 * 跟据学历提额分数获得额度
	 * 
	 * @param score
	 * @return
	 */
	public static Double getUpgradeMoneyByEducation(String arrangement) {
		int score = getScoreByEducationArrangement(arrangement);

		Double result = 0d;
		if (score > 40)
			result = 1500d;
		else if (score > 35)
			result = 1300d;
		else if (score > 30)
			result = 1000d;
		else if (score > 25)
			result = 800d;
		else if (score > 20)
			result = 500d;
		else if (score > 15)
			result = 400d;
		else if (score > 0)
			result = 300d;
		return result;
	}

	/**
	 * 跟据滴滴提额分数获得额度
	 * 
	 * @param score
	 * @return
	 */
	public static Double getUpgradeMoneyByDiditaxi(int score) {
		Double result = 0d;
		if (score > 80)
			result = 3000d;
		else if (score > 60)
			result = 2500d;
		else if (score > 40)
			result = 2000d;
		else if (score > 20)
			result = 1500d;
		else if (score > 10)
			result = 1000d;
		else if (score > 0)
			result = 500d;
		return result;
	}

	/**
	 * Taobao会员等分
	 * 
	 * @param vipLevel
	 * @return
	 */
	public static int getScoreByTaobaoVipLevel(int vipLevel) {
		int result = 0;

		switch (vipLevel) {
			case 0 :
				result = 50;
				break;

			case 1 :
				result = 75;
				break;

			case 2 :
				result = 80;
				break;

			case 3 :
				result = 85;
				break;

			case 4 :
				result = 90;
				break;

			case 5 :
				result = 95;
				break;

			case 6 :
				result = 100;
				break;
		}

		return result;
	}

	/**
	 * 花呗额度
	 * 
	 * @param huabeiLimit
	 * @return
	 */
	public static int getScoreByHuabeiLimit(Double huabeiLimit) {
		int result = 0;
		if (huabeiLimit > 40000)
			result = 100;
		else if (huabeiLimit > 30000)
			result = 95;
		else if (huabeiLimit > 20000)
			result = 90;
		else if (huabeiLimit > 15000)
			result = 85;
		else if (huabeiLimit > 10000)
			result = 80;
		else if (huabeiLimit > 8000)
			result = 75;
		else if (huabeiLimit > 5000)
			result = 70;
		else if (huabeiLimit > 3000)
			result = 65;
		else if (huabeiLimit > 500)
			result = 60;
		return result;
	}

	/**
	 * 社保分
	 * 
	 * @param socialsecurity
	 * @return
	 */
	public static int getScoreBySocialsecurity(int socialsecurity) {
		int result = 0;
		if (socialsecurity > 120)
			result = 50;
		else if (socialsecurity > 60)
			result = 40;
		else if (socialsecurity > 49)
			result = 30;
		else if (socialsecurity > 37)
			result = 25;
		else if (socialsecurity > 25)
			result = 20;
		else if (socialsecurity > 13)
			result = 15;
		else if (socialsecurity > 0)
			result = 10;
		return result;
	}

	/**
	 * 滴滴出行 近3个月出行次数
	 * 
	 * @return
	 */
	public static int getScoreByDidiTaxiCount(Integer didiTaxiCount) {
		int result = 0;
		if (didiTaxiCount > 20)
			result = 50;
		else if (didiTaxiCount > 10)
			result = 30;
		else if (didiTaxiCount > 5)
			result = 20;
		else if (didiTaxiCount > 0)
			result = 10;
		return result;
	}

	/**
	 * 滴滴出行 近3个月消费金额
	 * 
	 * @return
	 */
	public static int getScoreByDidiTaxiAmt(Double didiTaxiAmt) {
		int result = 0;
		if (didiTaxiAmt > 300)
			result = 50;
		else if (didiTaxiAmt > 200)
			result = 40;
		else if (didiTaxiAmt > 100)
			result = 30;
		else if (didiTaxiAmt > 50)
			result = 20;
		else if (didiTaxiAmt > 0)
			result = 10;
		return result;
	}

	/**
	 * 手机在网时长
	 * 
	 * @param args
	 */
	public static int getScoreByMobileRegisterDate(String mobileRegisterDate) {
		int result = 0;

		int countMonth = DateUtil.getMonthDiff(mobileRegisterDate);

		if (countMonth > 36)
			result = 5;
		else if (countMonth > 24)
			result = 4;
		else if (countMonth > 12)
			result = 3;
		else if (countMonth > 3)
			result = 2;
		else if (countMonth > 0)
			result = 1;
		return result;
	}

	/**
	 * 公积金分数
	 * 
	 * @param args
	 */
	public static int getScoreByHouseFund(String accStatus) {
		int result = 0;

		switch (accStatus) {
			case "正常" :
				result = 40;
				break;
			case "封存" :
				result = 30;
				break;
			case "销户" :
				result = 10;
				break;
		}

		return result;
	}

	/**
	 * 跟据基础分数获得额度
	 * 
	 * @param score
	 * @return
	 */
	public static Double getMoneyByBaseScore(int score) {
		double money = 0d;

		if (score > 990)
			money = 30000d;

		else if (score > 960)
			money = 29000d;

		else if (score > 940)
			money = 28000d;

		else if (score > 920)
			money = 27000d;

		else if (score >= 900)
			money = 26000d;

		else if (score > 840)
			money = 25000d;

		else if (score >= 800)
			money = 24000d;

		else if (score > 780)
			money = 23000d;

		else if (score > 770)
			money = 22000d;

		else if (score > 760)
			money = 21000d;

		else if (score > 750)
			money = 20000d;

		else if (score > 730)
			money = 19000d;

		else if (score >= 700)
			money = 18000d;

		else if (score > 660)
			money = 17000d;

		else if (score > 630)
			money = 16000d;

		else if (score > 599)
			money = 15000d;

		else if (score > 590)
			money = 14000d;

		else if (score > 580)
			money = 13000d;

		else if (score > 570)
			money = 12000d;

		else if (score > 560)
			money = 11000d;

		else if (score > 550)
			money = 10000d;

		else if (score > 540)
			money = 9000d;

		else if (score > 530)
			money = 8000d;

		else if (score > 520)
			money = 7000d;

		else if (score > 510)
			money = 6000d;

		else if (score >= 500)
			money = 5000d;
		else
			money = 0d;

		return money;
	}

	/**
	 * 跟据提额分数获得额度
	 * 
	 * @param score
	 * @return
	 */
	public static Double getMoneyByUpgradeScore(int score) {
		Double money = 0d;
		if (score >= 900)
			money = 20000d;
		else if (score >= 800)
			money = 19000d;
		else if (score >= 700)
			money = 18000d;
		else if (score >= 600)
			money = 17000d;
		else if (score >= 500)
			money = 16000d;
		else if (score >= 400)
			money = 15000d;
		else if (score >= 350)
			money = 14000d;
		else if (score >= 300)
			money = 13000d;
		else if (score >= 250)
			money = 12000d;
		else if (score >= 200)
			money = 10000d;
		else if (score >= 150)
			money = 7000d;
		else if (score >= 100)
			money = 5000d;
		else if (score >= 50)
			money = 3000d;
		else if (score >= 1)
			money = 2000d;

		return money;
	}

	/**
	 * 通过芝麻反欺诈详情代码返回相应的分数
	 * 
	 * @param code
	 * @return
	 */
	public static int getScoreByZhimaCreditIvsDetail(String code) {

		int result = 0;

		switch (code) {
			case "CERTNO_Match_Sharing_Good" :
			case "CERTNO_Match_Trust_Self_Sharing_Good" :
			case "CERTNO_Match_Recency_Good" :
			case "CERTNO_Match_Trust_Self_Recency_Good" :
			case "CERTNO_Match_Reliability_Good" :
			case "CERTNO_Match_Trust_Self_Reliability_Good" :
			case "NAME_Match_Sharing_Good" :
			case "NAME_Match_Recency_Good" :
			case "NAME_Match_Reliability_Good" :
			case "PHONE_Match_Sharing_Good" :
			case "PHONE_Match_Trust_Self_Sharing_Good" :
			case "PHONE_Match_Recency_Good" :
			case "PHONE_Match_Trust_Self_Recency_Good" :
			case "PHONE_Match_Reliability_Good" :
			case "PHONE_Match_Trust_Self_Reliability_Good" :
				// 无风险
				result = 10;
				break;

			case "CERTNO_Match_Recency_Bad" :
			case "CERTNO_Match_Trust_Self_Recency_Bad" :
			case "PHONE_Match_Recency_Bad" :
			case "PHONE_Match_Trust_Self_Recency_Bad" :
			case "PHONE_Match_Trust_Other" :
				// 低风险
				result = 8;
				break;

			case "CERTNO_Match_Sharing_Bad" :
			case "CERTNO_Match_Trust_Self_Sharing_Bad" :
			case "CERTNO_Match_Reliability_Bad" :
			case "CERTNO_Match_Trust_Self_Reliability_Bad" :
			case "NAME_Match_Sharing_Bad" :
			case "NAME_Match_Recency_Bad" :
			case "NAME_Match_Reliability_Bad" :
			case "PHONE_Match_Sharing_Bad" :
			case "PHONE_Match_Trust_Self_Sharing_Bad" :
			case "PHONE_Match_Reliability_Bad" :
			case "PHONE_Match_Trust_Self_Reliability_Bad" :
				// 中风险
				result = 5;
				break;

			case "CERTNO_Match_Trust_Other_Sharing_Good" :
			case "CERTNO_Match_Trust_Other_Sharing_Bad" :
			case "CERTNO_Match_Trust_Other_Recency_Good" :
			case "CERTNO_Match_Trust_Other_Recency_Bad" :
			case "CERTNO_Match_Trust_Other_Reliability_Good" :
			case "CERTNO_Match_Trust_Other_Reliability_Bad" :
			case "CERTNO_Mismatch" :
			case "CERTNO_History_NegativeList" :
			case "NAME_Mismatch" :
			case "PHONE_Mismatch" :
			case "PHONE_History_NegativeList" :
				// 高风险
				result = 0;
				break;

			case "CERTNO_Missing" :
			case "PHONE_Missing" :
				// 未知风险
				result = 2;
				break;
		}

		return result;
	}

	public static void main(String[] args) {
	}

}
